﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Blogical.Tools.BizTalkUndeployHelper
{
    [Serializable]
    public class AssemblyResource:IComparable
    {
        static int count;
        public AssemblyResource() { }
        public AssemblyResource(string luid)
        {
            this.Luid = luid;
        }
        public string Luid { get; set; }
        public string Application { get; set; }
        public List<string> DependsOn = new List<string>();
        public List<AssemblyResource> DependsOnAssemblies = new List<AssemblyResource>();
        public bool Selected;

        bool IsDependantOn(AssemblyResource assemblyResource)
        {
            if (this.DependsOn.Contains(assemblyResource.Luid))
                return true;

            foreach (AssemblyResource ar in this.DependsOnAssemblies)
            {
                if (ar.Luid == "CustCom.MPoint1CustCom.Schemas")
                    Console.WriteLine("");
                if (ar.IsDependantOn(assemblyResource))
                    return true;
            }
            return false;
        }

        public int CompareTo(object obj)
        {
            AssemblyResource assemblyResource = (AssemblyResource)obj;

            bool isDependant = this.IsDependantOn(assemblyResource);
            
            if (isDependant)
                return 1;
            else
                return -1;

        } 
    }
}
